<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<script type="text/javascript" src="./js/qrcode.min.js"></script>
		<script type="text/javascript" src="//cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
		<script type="text/javascript" src="./js/common.js"></script>
	</head>
	<body>
		<div class="container bg-white">
			<div class="bg-dark mui-text-center pdt-5 pdb-5 pos-relative logo-content">
				<div class="bg-dark flex flex-jc-around pdt-10 pd-10 pos-relative">
					<img src="./img/arbicap_logo.png" style="height: 80px" alt="">
					<h1 style="height: 80px;line-height: 80px;" class="cl-white">阿尔卑斯</h1>
				</div>
			</div>
			<div class="flex flex-center flex-wrap">
				<h1 class="mui-text-center mgt-20 w100">我的邀请码</h1>
				 <a id="downloadLink"></a>
				<div id="qrcode" style=" margin-top:15px;"></div>
				<div class="mgt-10 pd-10 flex flex-jc-around code w100" style="letter-spacing: 5px;font-size: 40px">
					<!-- 我的邀请码 -->
				</div>
			</div>
		</div>
		<script>
			mui('.logo-content').on('click', 'div', function() {
				location.href = './index.html'
			})

			const code = localStorage.getItem('CODE')
			mui('.code')[0].innerHTML = code

			var qrcode = new QRCode("qrcode", {
				text: code,
				render: 'canvas',
				width: 128,
				height: 128,
				colorDark: "#000000",
				colorLight: "#ffffff",
				correctLevel: QRCode.CorrectLevel.H
			});

			qrcode.clear(); // 清除代码
			qrcode.makeCode(WEBHOST + 'register.html?code=' + code);
			
			function downloadClick() {
				// 获取base64的图片节点
				var img = document.getElementById('qrcode').getElementsByTagName('img')[0];
				// 构建画布
				var canvas = document.createElement('canvas');
				canvas.width = img.width;
				canvas.height = img.height;
				canvas.getContext('2d').drawImage(img, 0, 0);
				// 构造url
				url = canvas.toDataURL('image/jpg');
				// 构造a标签并模拟点击
				var downloadLink = document.getElementById('downloadLink');
				downloadLink.setAttribute('href', url);
				downloadLink.setAttribute('download', '二维码.png');
				downloadLink.click();
			}
			mui('body').on('click','#qrcode',function(){
				downloadClick()
			})
			
		</script>
	</body>
</html>
